<script src="{{ getAssets }}js/bivariatetable/bivariatetable.js" type="text/javascript"></script>
<script type="text/javascript">
var goods_id = '{{.goods_id}}';
var entry_id = '{{.entry_id}}';
var middle_id = '{{.middle_id}}';
var goods_function_info;
var goods_mouting_genre;
var typeid = 30;
$(function(){
	$.post('{{ urlfor "ErpEntryController.MountingAdd" }}',{'goods_id':goods_id, 'middle_id': middle_id}, function(res){
		if(res.code == 0) {
			$('#goods-title').html(productGroupName(res.data.goods));
			middle_data = res.data.middle
			typeid = res.data.goods.TypeId;
			$.post('{{ urlfor "ProductsController.GetOptions"}}', {'fields':['goods_function_info', 'goods_mouting_genre']}, function(res){
				goods_mouting_genre = res.data.goods_mouting_genre;
				goods_function_info = res.data.goods_function_info;
				if(middle_data == null) {
					for(i=0;i<=7;i++){
						$('#addline').click();
					}
				} else {
					$('#attrlist').html('');
					$.each(middle_data, function(index, value){
						addTrLine(value);
					});	
				}
				colShowHide();
			});	
		}
	}, 'json');
	
});

function colShowHide() {
	if(typeid == 30) {
		$('.f40').hide();
	} else if(typeid == 41){
		$('.f40').show();
	}	
}
function setOptions(data ,def) {
	var opt = '<option value=""></option>';
	$.each(data, function(index, value){
		opt += '<option value="'+ value.val +'" '+ (def==value.val ? 'selected':'') +'>'+ value.val +'</option>';
	});
	return opt;
}

function addTrLine(data) {
    var tr = '<tr><td><input type="checkbox" value=""  class="checkboxs"/></td>\
			 <td><input name="model_number[]" class="model_number" type="text"  value="'+ (data.Snd ? data.Snd.model :'') +'" /></td>\
			 <td><input name="colour_number[]" class="colour_number" type="text"  value="'+ (data.Snd ? data.Snd.color :'') +'" /></td>\
			 <td><input name="size[]" class="size" type="text"  value="'+ (data.Snd ? data.Snd.size :'') +'" /></td>\
			 <td width="130" class="f40"><select name="function_info[]" class="function_info">'+ setOptions(goods_function_info, (data.Snd ? data.Snd.function_info :'')) +'</select></td>\
			 <td class="f40"><input name="film_color[]" class="film_color" type="text"  value="'+ (data.Snd ? data.Snd.film_color :'') +'" /></td>\
			 <td width="80"><select class="genre" name="genre[]">'+ setOptions(goods_mouting_genre, (data.Snd ? data.Snd.genre :'')) +'</select></td>\
			 <td><input name="purchase_num[]" class="purchase_num" type="number"  value="'+ data.purchase_num +'" /></td></tr>';
	$('#attrlist').append(tr);		 
	return tr;
}
</script>